# coding=utf-8

import os,optparse

def convert(srcdir,todoExt=()):
  for root, dirs, files in os.walk(srcdir):
    for file in files:
      (fileName,fileExt) = os.path.splitext(file)
      fileExt = fileExt.lower()[1:]
      abfile = os.path.join(root,file)

      if not todoExt or (fileExt in todoExt):
        print('processing %s : ' % abfile,end = '')
        data = open(abfile, 'rb').read()
        data = data.replace(b'\n', b'\r\n')
        open(abfile, 'wb').write(data)
        print('done')


if __name__ == '__main__':
  parser = optparse.OptionParser()
  parser.add_option('-d','--dir',dest="dir",help="dir")
  parser.add_option('-e','--ext',dest="ext",help="ext")

  options, _ = parser.parse_args()
  if not options.dir:
    options.dir = input("input dir:")
  if not options.ext:
    options.ext = ()

  convert(options.dir,options.ext)
